import { Module } from '@nestjs/common';
import { AuthorizeService } from './authorize.service';
import { AuthorizeController } from './authorize.controller';
import { UsersModule } from '../users/users.module';
import { JwtModule } from '@nestjs/jwt';
import { jwtConstants } from './constants';
import { AuthorizeGuard } from './authorize.guard';
import { APP_GUARD } from '@nestjs/core';
import { TokensModule } from 'src/tokens/tokens.module';
import { EmailModule } from 'src/email/email.module';
import { EmailService } from 'src/email/email.service';

@Module({
  imports: [
    UsersModule,
    TokensModule,
    JwtModule.register({
      global: true,
      secret: jwtConstants.secret,
      signOptions: { expiresIn: jwtConstants.expiresIn },
    }),
    EmailModule, // 引入 EmailModule 并在 providers 数组中添加 EmailService 实例
  ],
  controllers: [AuthorizeController],
  providers: [
    AuthorizeService,
    /** 注册全局守卫 */
    {
      provide: APP_GUARD,
      useClass: AuthorizeGuard,
    },
    EmailService,
  ],
  exports: [AuthorizeService],
})
export class AuthorizeModule {}
